package www.test.com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import www.test.com.config.RedisConfig;
import www.test.com.entity.User;
import www.test.com.service.IUserService;

import java.time.Duration;
import java.util.List;

@RestController
public class UserController {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @Autowired
    private IUserService userService;

    @RequestMapping("/testUser")
    @ResponseBody
    public String testController(){
        return "HelloWorld";
    }

    @GetMapping("/findAll")
    @ResponseBody
    public List<User> findAll(){
        return userService.list();
    }

    @GetMapping("/getRedis")
    public String getRedis(){
        redisTemplate.opsForValue().set("id","123456", Duration.ofMillis(60000));
        return (String) redisTemplate.opsForValue().get("id");
    }

}
